// 用户相关的小仓库
import { defineStore } from "pinia";
// 引入接口
import { reqMenuInfo } from "@/api/admin/menu/index";
// 引入数据类型
import type { MenuForm, MenuResponseData } from "@/api/admin/menu/type";
import type { MenuState } from "./type";

const useMenuStore = defineStore("Menu", {
  state: (): MenuState => {
    return {
      menuList: [], // 菜单
    };
  },
  getters: {},
  actions: {
    // 获取菜单
    async userMenu(data: MenuForm) {
      let res: MenuResponseData = await reqMenuInfo(data);
      if (res.code == 200) {
        this.menuList = res.data;
        return "ok";
      }
      return Promise.reject(new Error(res.msg));
    },
  },
  //开启本地存储
  persist: {
    //默认名称为当前store唯一标识 这里即home
    key: "menu",
    //默认 localStorage 本地储存
    //这里建议临时储存sessionStorage 也可写成window.sessionStorage
    storage: sessionStorage,
    //默认当前store里的所有变量都持久化
    // paths: ["num"],
  },
});

export default useMenuStore;
